package com.study.d012Components.dialog;

import java.awt.Label;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/** 自定义弹出模态框
*@description
*@author xtayhame
*date 2020年3月14日
*version
*since v1.0
*/
public class DialogCustomizeMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();

		Button button  = new Button("弹窗");

		anchorPane.getChildren().add(button);
		AnchorPane.setTopAnchor(button, 30.0);
		AnchorPane.setLeftAnchor(button, 30.0);

		stage.setScene(new Scene(anchorPane,400,300));
		stage.show();

		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				AnchorPane  an = new AnchorPane();

				VBox vBox = new VBox(10);

				HBox hBox1 = new HBox(30);

				hBox1.getChildren().add(new javafx.scene.control.Label("恭喜你，答对了."));

				HBox hBox2 = new HBox(30);

				hBox2.getChildren().add(new Button("关闭"));

				hBox2.getChildren().add(new Button("确定"));

				vBox.getChildren().addAll(hBox1,hBox2);

				an.getChildren().add(vBox);

				Stage stageModel = new Stage();
				Scene sceneModel = new Scene(an,400,300);
				stageModel.setScene(sceneModel);

				stageModel.initOwner(stage);
				stageModel.setTitle("自定义消息提示框");
				//设置为模态框
				stageModel.initModality(Modality.WINDOW_MODAL);
				//默认总在上面
				stageModel.setAlwaysOnTop(true);
				//只保留右上角关闭按钮
				stageModel.initStyle(StageStyle.UTILITY);

				stageModel.show();
			}
		});

	}
}
